﻿/// <reference path="../dal/sca.dal.sp.js" />

var SCA = SCA || {};

SCA.SPDialog = function (title, siteCollectionUrl, callback) {

    this.title = title;
    this.callback = callback;
    this.siteCollectionUrl = siteCollectionUrl;

    var thisContext = this;

    this.web;

    this.OpenAssetPicker = function () {
        this.web = new SCA.DAL.Web(this.siteCollectionUrl);
        this.web.Load(Function.createDelegate(this, OpenAssetPickerDialog), Function.createDelegate(this, onFailLoadWeb));
    }

    var onFailLoadWeb = function () {
        alert("SCA.SPDialog - OpenAssetPicker(): fail loading web");
    }

    var OpenAssetPickerDialog = function () {
        var webId = this.web.id;
        var serverRelativeUrl = this.siteCollectionUrl.substring(this.web.serverUrl.length);
        var assetPickerUrl = this.siteCollectionUrl + '/_layouts/AssetPortalBrowser.aspx?&AssetUrl=' + serverRelativeUrl + '&RootFolder=' + serverRelativeUrl + '&MDWeb=' + webId + '&AssetType=Link';

        var options = SP.UI.$create_DialogOptions();
        options.url = assetPickerUrl;
        options.dialogReturnValueCallback = Function.createDelegate(null, this.callback);
        options.width = 800;
        options.height = 600;
        options.title = this.title;

        SP.UI.ModalDialog.showModalDialog(options);
    }
};
